//
//  ViewController.m
//  05-九宫格
//
//  Created by apple on 15/7/22.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import "ViewController.h"
#import "LMPerson.h"
#import "LMPersonView.h"
@interface ViewController ()
/**app对象数组*/
@property (nonatomic,strong) NSArray *apps;

@end

@implementation ViewController


- (NSArray *)apps{
    if (_apps==nil) {
        
        
        _apps = [LMPerson appsList];
    }
    return  _apps;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    for(int i = 0;i<self.apps.count;i++)
    {
//        UIView *subView = [[UIView alloc] init];
//        [self.view addSubview:subView];
//        UIView *subView=[[[NSBundle mainBundle] loadNibNamed:@"LMPerson" owner:nil options:nil] lastObject];
        
//        LMPersonView *subView =[[[NSBundle mainBundle] loadNibNamed:@"LMPerson" owner:nil options:nil] lastObject];
        LMPersonView *subView = [LMPersonView appInfoView];
        
        [self.view addSubview:subView];
        
        CGFloat subViewW = 100;
        CGFloat subviewH = 110;
        
        CGFloat marginX = (self.view.frame.size.width-3*subViewW)/4;
        
        CGFloat marginY = 20;
        
        int row = i/3;
        
        int column = i%3;
        
        CGFloat subViewX = marginX + column*(marginX + subViewW);
        CGFloat subVIewY = 30 + row * (marginY + subviewH);
        
        subView.frame = CGRectMake(subViewX, subVIewY, subViewW, subviewH);
        
        // subView.backgroundColor = [UIColor redColor];
        
        
        
        //NSDictionary *dic = self.apps[i];
        
        LMPerson *person = self.apps[i];
//        subView.appInfo = person;
        
        [subView setAppInfo:person];
        
        
        
//        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, subViewW, 70)];
//        UIImageView *imageView = (UIImageView *)[subView viewWithTag:1];
//        UIImageView *imageView = subView.iconName;
//        imageView.image = [UIImage imageNamed:person.icon];
        
//        imageView.contentMode = UIViewContentModeScaleAspectFit;
        
//        [subView addSubview:imageView];
        
//        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, imageView.bounds.size.height, subViewW, 20)];
        
//        UILabel *label= (UILabel *)[subView viewWithTag:2];
//        UILabel *label= subView.labelName;
        
//        label.text = person.name;
//        label.font = [UIFont systemFontOfSize:12];
//        label.textAlignment = NSTextAlignmentCenter;
        
//        [subView addSubview:label];
        
        
//        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 88, subViewW, 20)];
        
//        UIButton *button= (UIButton *)[subView viewWithTag:3];
//        UIButton *button = subView.buttonName;
        
        
//        
//        [button setTitle:@"下载" forState:UIControlStateNormal];
//        
//        button.titleLabel.font = [UIFont systemFontOfSize:14];
//        
//        [button setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];
//        
//        [button setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted];
//        [subView addSubview:button];
//        
//        button.tag = i ;
//        
//        [button addTarget:self action:@selector(donghuaWithButton:) forControlEvents:UIControlEventTouchUpInside];
        
        
    }
}

//- (void) donghuaWithButton:(UIButton *) button{
//    
//    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(60, 400, 200, 20)];
//    
//    lable.textAlignment = NSTextAlignmentCenter;
//    
//    lable.font = [UIFont systemFontOfSize:13];
//    
//    [lable setBackgroundColor:[UIColor redColor]];
//    
//    //    NSDictionary *dicc = self.apps[button.tag];
//    LMPerson *person = self.apps[button.tag];
//    lable.text = [NSString stringWithFormat:@"%@下载完成",person.name];
//    
//    lable.alpha=1.0;
//    [self.view addSubview:lable];
//    
//    
//    
//    [UIView animateWithDuration:1.0 animations:^{
//        lable.alpha = 0.0;
//    } completion:^(BOOL finished){
//        
//        [lable removeFromSuperview];
//        
//        
//    }];
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
